package cn.cloud.butler.scheduled.configuration;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 日期时间 工具类
 */
public class DateTimeUtil {

    public static String getYesterDay(){
        //获取昨天的时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24);
        return simpleDateFormat.format(today);
    }
    public static String getToDay(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(today);
    }
    public static Boolean isSameDay(String day1,Long day2){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date inday=new Date(day2);
        String iStr=simpleDateFormat.format(inday);
        return day1.equals(iStr);
    }
    public static Boolean isToday(Long milisecond){
        //获取昨天的时间
        Long current=System.currentTimeMillis();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date(System.currentTimeMillis());
        Date inday=new Date(milisecond);
        String tStr=simpleDateFormat.format(today);
        String iStr=simpleDateFormat.format(inday);
        return tStr.equals(iStr);
    }
    public static String getLastDay(){
        //获取前天的时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 2 );
        return sdf.format(today);
    }


    public static String getSysTime(){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date = new Date();
        String dateStr = sdf.format(date);

        return dateStr;

    }

    public static String nowStrTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String datestr = sdf.format(date);
        return datestr;
    }

    public static String getSysTimeForUpload(){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

        Date date = new Date();
        String dateStr = sdf.format(date);

        return dateStr;

    }
    // 将时间格式转化为字符串
    public static String getSysTimeForUpload(String date){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

        String dateStr = sdf.format(date);

        return dateStr;

    }
    //计算时间差
    public static long timeDif(String time1,String time2) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-M-d HH:mm:ss");//设置获取时间格式
        long i = 0;
        try {
            Date dt1 = formatter.parse(time1);
            Date dt2 = formatter.parse(time2);
            long l = dt2.getTime() - dt1.getTime();
            i = -(l / (1000));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return i;

    }
}
